package Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pojo.Consumer;
import service.ConsumerService;

@RestController
public class ConsumerController {
    @Autowired
    private ConsumerService consumerService;
    /**
     *管理界面调用：返回所有用户
     */
    @GetMapping("/user")
    public R allUser(@RequestParam(defaultValue = "1") int curPage,@RequestParam(defaultValue = "1") int pageSize) {
        IPage<Consumer> page = new Page<>();
        //设置当前页
        page.setCurrent(curPage);
        //设置每页显示数据条数
        page.setSize(pageSize);
        return consumerService.allUser(page);
    }
    /**
     *删除用户
     */
    @GetMapping("/user/delete")
    public R deleteUser(@RequestParam int id) {
        return consumerService.deleteUser(id);
    }

    @DeleteMapping("user/deleteIds")
    public R deleteUsers(@RequestParam String[] id){
        return consumerService.deleteUsers(id);
    }

}
